package org.crud4j.core.annotation;

import java.util.Date;

/**
 * Enumeration of available editors
 */
public enum FieldEditor {

	DEFAULT("default.jsp"), BOOLEAN("boolean.jsp"), NUMBER("number.jsp"), DATE(
			"date.jsp"), FK("fk.jsp"), CRUDFK("crudfk.jsp");

	private String page;

	private FieldEditor(String page) {
		this.page = page;
	}

	public String getPage() {
		return page;
	}

	public static FieldEditor getDefaultEditor(Class type) {

		FieldEditor editor = FieldEditor.DEFAULT;

		if (type.equals(Date.class)) {
			editor = DATE;
		}

		if (type.equals(Boolean.class)) {
			editor = BOOLEAN;
		}

		if (type.equals(Integer.class) || type.equals(Short.class)
				|| type.equals(Long.class) || type.equals(Double.class)) {
			editor = NUMBER;
		}

		return editor;
	}

}
